<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('代理商费率模版列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 100px;">费率模板编号：</label>
                                <input type="text" name="arMark"/>
                            </li>
                            <li>
                                <label style="width: 100px;">是否默认：</label>
                                <select name="isdefault" th:with="type=${@dict.getType('isDefault')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 100px;">费率模板名称：</label>
                                <input type="text" name="arName"/>
                            </li>
                            <li>
                                <label style="width: 100px;">产品类型：</label>
                                <select name="merType" th:with="type=${@dict.getType('modelType')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 10px;"></label>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add(650,950,null)" shiro:hasPermission="agentRateInfo:agentRateInfo:add">
                    <i class="fa fa-plus"></i> 新增模版
                </a>
               <!-- <a class="btn btn-success" onclick="addInitModel()" shiro:hasPermission="agentRateInfo:agentRateInfo:initAdd">
                    <i class="fa fa-plus"></i> 初始化模版
                </a>-->
                <a class="btn btn-primary single disabled" onclick="$.operate.edit(null,650,950)" shiro:hasPermission="agentRateInfo:agentRateInfo:edit">
                    <i class="fa fa-edit"></i> 修改模版
                </a>
                <a class="btn btn-primary single disabled" onclick="setModelDetailsRate()" shiro:hasPermission="agentRateInfo:agentRateInfo:add">
                    <i class="fa fa-edit"></i> 费率模板详情
                </a>
                <a class="btn btn-primary single disabled" onclick="setModelDetailsRateFj()" shiro:hasPermission="agentRateInfo:agentRateInfo:add">
                    <i class="fa fa-edit"></i> 附加模板详情
                </a>
              <!--  <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="agentRateInfo:agentRateInfo:remove">
                    <i class="fa btn-success"></i> 设置默认模版
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" class="table text-nowrap"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('agentRateInfo:agentRateInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('agentRateInfo:agentRateInfo:remove')}]];
        var isdefaultDatas = [[${@dict.getType('isDefault')}]];
        var merTypeDatas = [[${@dict.getType('proType')}]];
        var agentNumHidden = [[${@permission.hasPermi('merchant:merchant:model')}]];

        var prefix = ctx + "agentRateInfo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "代理商费率模版",
                firstLoad:true,
                clickToSelect:true,
                columns: [{
                    radio: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'agentNum',
                    title: '代理编号',
                    visible: agentNumHidden == 'hidden' ? false : true,

                },
              /*  {
                    field: 'arMark',
                    title: '费率模板编号',
                    align: 'center'
                },*/
                {
                    field: 'arName',
                    title: '费率模板名称',
                    align: 'center'
                },
               /* {
                    field: 'fjArMark',
                    title: '附加费率编号',
                    align: 'center'
                },*/
                {
                    field: 'fjArMarkName',
                    title: '附加费',
                    align: 'center'
                },
                {
                    field: 'isdefault',
                    title: '是否默认',
                    formatter: function (value, row, index) {
                        return statusTools(row,row.id,row.agentNum);
                    },
                    align: 'center'
                },
               /* {
                    field: 'merType',
                    title: '产品类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(merTypeDatas, value);
                    },
                    align: 'center'
                },*/
                {
                    field: 'addDate',
                    title: '添加时间',
                    align: 'center'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
/*
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
*/
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除模版</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /**
         * 删除模版
         */
        function remove(id) {
            $.modal.confirm("确定要删除当前模版？", function() {
                var isdefault = $.table.selectColumns("isdefault");
                if (isdefault == '0'){
                    $.modal.msgError("不可删除默认模版");
                    return;
                }
                var data = {"id": id};
                $.operate.post(prefix + "/remove", data);
            })
        }

        function setModelDetailsRate() {
            var arMark = $.table.selectColumns("arMark");
            $.modal.details("模板模板详情", ctx + "merchant/merchantModel/setModelDetailsRate?type=1&modelNo="+arMark,"1100","700");
        }
        function setModelDetailsRateFj() {
            var fjArMark = $.table.selectColumns("fjArMark");
            $.modal.details("附加模板详情", ctx + "merchant/merchantModel/addFj?type=1&modelNo="+fjArMark,"800","350");

        }

        /**
         * 初始化顶级代理模版
         */
        function addInitModel(){
            $.modal.open("初始化模版", prefix + "/addInitModel","950","650");
        }

        function statusTools(row,id,agentNum) {
            if (row.isdefault == 1) {
                return '<i  style="position:relative;top:4px;left: 5px;" class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row + '\',\'' + id + '\',\'' + agentNum + '\')"></i> ';
            } else {
                return '<i  style="position:relative;top:4px;left: 5px;" class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row + '\',\'' + id + '\',\'' + agentNum + '\')"></i> ';
            }
        }

        /* 冻结 */
        function disable(row,id,agentNum) {
            $.modal.confirm("确认要取消默认吗？", function() {
                $.operate.post(prefix + "/updateDefault", { "isdefault": "1","agentNum": agentNum,"id": id});
            })
        }

        /* 解冻 */
        function enable(row,id,agentNum) {
            $.modal.confirm("确认要设置默认吗？", function() {
                $.operate.post(prefix + "/updateDefault", { "isdefault": "0","agentNum": agentNum,"id": id});
            })
        }

    </script>



</body>
</html>